import { getAddressList } from '@/api/address'
// 收货地址
export default {
  namespaced: true,
  state () {
    return {
      addressList: []
    }
  },
  getters: {
    // 选中的收货地址
    selectedAddress (state) {
      return state.addressList[0] || {}
    },
    // 收货地址
    logAddress (state, getters) {
      const { province, city, region } = getters.selectedAddress.region
      return province + ' ' + city + ' ' + region + ' ' + getters.selectedAddress.detail
    }
  },
  mutations: {
    setAddressList (state, newList) {
      state.addressList = newList
    }
  },
  actions: {
    // 请求收货地址列表接口
    async getAddressList (context) {
      const { data: { list } } = await getAddressList()
      context.commit('setAddressList', list)
    //   console.log(list)
    }
  }
}
